define(function(require, exports, module) {
	var $ = require('$');
	var formcc = require('form');
	var nav = require("bootstrap_nav");
	var bootbox = require("bootbox");
	var loader = require("./loader/loader");
	require("bootstrap-datetimepicker.min.css");
	// require("bootstrap_datetimepicker.zh-CN");
	require("bootstrap_datetimepicker");
	require('select2.css');
	require('select2');
	exports.init = function(divId) {
	new formcc({
		attrs : {
			title : "新建短信签名",
			spansize : 'span12',
			id : "adddatainfoform",
			items : [ {
				isText : true,
				label : "签名编号",
				id : 'signcodeAdd',
				name : 'signcodeAdd',
				type : "text",
				style : "width:50%",
				readonly : false,
				validations : {
					required : true,
					minlength : 2,
					maxlength:15
				}
			}, {
				isText : true,
				label : "签名位置",
				id : 'positionAdd',
				name : 'positionAdd',
				type : "text",
				style : "width:50%",
				placeholder : "请输入签名位置",
				validations : {
					required : true,
					minlength : 2
				}
			}, {
				isText : true,
				label : "下发号码",
				id : 'ext_numberAdd',
				name : 'ext_numberAdd',
				type : "text",
				style : "width:50%",
				placeholder : "请输入下发号码",
				validations : {
					required : true,
					minlength : 1,
					maxlength:6
				}
			}, {
				isText : true,
				label : "签 名内容",
				id : 'signatureAdd',
				name : 'signatureAdd',
				type : "text",
				style : "width:50%",
				placeholder : "请输入签 名内容",
				validations : {
					required : true,
					minlength : 1,
					maxlength:10
				}
			}, {
				isText : true,
				label : "备注",
				id : 'commentsAdd',
				name : 'commentsAdd',
				type : "text",
				style : "width:50%"
			} ],
			buttons : [ {
				text : "保存",
				id : "btn_save",
				type : "submit",
				style : "btn btn-contrast",
				backgroud : "btn-contrast"
			}, {
				text : "取消",
				id : "btn_cancel",
				style : "btn",
				type : "button"
			} ]
		},
		renderTo : divId,
		afterRender : function() {
			// 初始化下拉框 ----- 
			$("#positionAdd").select2({
		          placeholder : "请选择签名位置",
		          allowClear : true,
		          data : [ {
		              "id" : "before",
		              "text" : "before"
		            }, {
		              "id" : "after",
		              "text" : "after"
		            }]
		        });

			var theme = require('bootstrap_theme');
			theme.setValidateForm($("#adddatainfoform"), saveAction);

			$('#btn_cancel').on('click', function() {
				$("#addForm").show();
				$("#queryAreaId").show();
				$("#datalist_data_table").show();
				$('#info_edit_table').hide();
			});
		}
		});
	};
	// 保存
	var saveAction = function() {
		var formdata = {
			signcode : $("#signcodeAdd").val(),
			position:$("#positionAdd").val(),
			ext_number:$("#ext_numberAdd").val(),
			signature : $("#signatureAdd").val(),
			comments : $("#commentsAdd").val()
		};
		loader.loading("正在创建中，请稍等……");
		$.ajax({
			url : "/smscontent/doInsertSignCode.do",// GLOBAL.URL.ADMIN_INSERTLICENSECARRIER,
			dataType : "json",
			data : "data=" + JSON.stringify(formdata),
			type : "POST",
			success : function(json) {
				if (json.flag == '000000') {
					nav.toPageView("sms/smsSigncode.html");
					loader.noloading();
				} else {
					loader.noloading();
					bootbox.alertTimeout("短信签名新增失败，失败原因可能为签 名标识重复，请重试！");
					//oauth2Relogin();
				}
			},
			error : function(s) {
				loader.noloading();
				bootbox.alertTimeout("网络请求失败，请重试！");
			}
		});

	};
});
